CFLAGS=-Wall -fno-strict-aliasing

all: modules utils

modules:
	mkdir -p mods
	gcc ${CFLAGS} -c pgconn.c -I/usr/include/pgsql -fPIC
	gcc ${CFLAGS} -c pam_pg_options.c -fPIC
	gcc ${CFLAGS} pam_pg.c -o mods/pam_pg.so pgconn.o pam_pg_options.o -lpam -lpq -lmhash -shared -fPIC
	gcc ${CFLAGS} pam_pg_su.c -o mods/pam_pg_su.so pgconn.o pam_pg_options.o -lpam -lpq -lmhash -shared -fPIC

utils:
	mkdir -p bin
	gcc ${CFLAGS} pg_common.c -c
	gcc ${CFLAGS} create_passwd.c -o bin/create_passwd pg_common.o -lpq
	gcc ${CFLAGS} create_shadow.c -o bin/create_shadow pg_common.o -lpq
	gcc ${CFLAGS} create_group.c -o bin/create_group pg_common.o -lpq
	gcc ${CFLAGS} adduserdb.c -o bin/adduserdb pg_common.o -lpq -lmhash
	gcc ${CFLAGS} deluserdb.c -o bin/deluserdb pg_common.o -lpq -lmhash
	gcc ${CFLAGS} moduserdb.c -o bin/moduserdb pg_common.o -lpq -lmhash
	gcc ${CFLAGS} delgroupdb.c -o bin/delgroupdb pg_common.o -lpq -lmhash
	gcc ${CFLAGS} modgroupdb.c -o bin/modgroupdb pg_common.o -lpq -lmhash
	gcc ${CFLAGS} addgroupdb.c -o bin/addgroupdb pg_common.o -lpq -lmhash

install:
	cp mods/*.so /lib/security/
	cp bin/* /usr/bin/

clean:	
	rm -f bin/* mods/* pgconn.o pg_common.o
